package aplicacao;


import classesBD.Conexao;
import javax.swing.JFileChooser;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.event.ActionListener;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Iterator;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Pessoal
 */
public class principal extends javax.swing.JFrame {

    /**
     * Creates new form principal
     */
    public principal() {
        initComponents();
        funcoes.carregaPesquisadores("pesquisadores.txt");
        txtPesquisadores.setText(funcoes.dumpPesq());
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    btnSelArquivo = new javax.swing.JButton();
    txtArquivo = new javax.swing.JTextField();
    jLabel1 = new javax.swing.JLabel();
    jInternalFrame1 = new javax.swing.JInternalFrame();
    jLabel3 = new javax.swing.JLabel();
    jScrollPane2 = new javax.swing.JScrollPane();
    txtPesquisadores = new javax.swing.JTextArea();
    btnCarregar = new javax.swing.JButton();
    lblTempo = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    btnSelArquivo.setText("Selecionar");
    btnSelArquivo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnSelArquivoActionPerformed(evt);
      }
    });

    txtArquivo.setText("G:\\Alan\\Monografia\\App\\dblp.xml");
    txtArquivo.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        txtArquivoActionPerformed(evt);
      }
    });

    jLabel1.setText("Arquivo da Base(DBLP)");

    jInternalFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    jInternalFrame1.setTitle("Limitar Pesquisadores Carregados");
    jInternalFrame1.setVisible(true);

    jLabel3.setText("Pesquisadores Selecionados");

    txtPesquisadores.setColumns(20);
    txtPesquisadores.setRows(5);
    jScrollPane2.setViewportView(txtPesquisadores);

    javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
    jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
    jInternalFrame1Layout.setHorizontalGroup(
      jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jInternalFrame1Layout.createSequentialGroup()
        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING)
          .addGroup(jInternalFrame1Layout.createSequentialGroup()
            .addComponent(jLabel3)
            .addGap(0, 0, Short.MAX_VALUE)))
        .addContainerGap())
    );
    jInternalFrame1Layout.setVerticalGroup(
      jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(jInternalFrame1Layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel3)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addContainerGap(143, Short.MAX_VALUE))
    );

    btnCarregar.setText("Realizar carga na base");
    btnCarregar.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        btnCarregarActionPerformed(evt);
      }
    });

    lblTempo.setText("Tempo Gasto:");

    jLabel2.setText("Info:");

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGroup(layout.createSequentialGroup()
            .addGap(30, 30, 30)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
              .addComponent(jLabel1)
              .addGroup(layout.createSequentialGroup()
                .addComponent(txtArquivo, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSelArquivo))
              .addComponent(jInternalFrame1)))
          .addGroup(layout.createSequentialGroup()
            .addGap(104, 104, 104)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addComponent(jLabel2)
              .addComponent(lblTempo))))
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addComponent(btnCarregar)
        .addGap(142, 142, 142))
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
        .addContainerGap()
        .addComponent(jLabel1)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
          .addComponent(txtArquivo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
          .addComponent(btnSelArquivo))
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
        .addComponent(btnCarregar)
        .addGap(18, 18, 18)
        .addComponent(lblTempo)
        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        .addComponent(jLabel2)
        .addContainerGap())
    );

    pack();
  }// </editor-fold>//GEN-END:initComponents

    timerProgresso t;
    private void txtArquivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtArquivoActionPerformed
      
    }//GEN-LAST:event_txtArquivoActionPerformed

    private void btnSelArquivoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSelArquivoActionPerformed
      String retorno;
      JFileChooser jFileChooser1 = new JFileChooser();
      jFileChooser1.setFileFilter(new FileNameExtensionFilter("Arquivos XML", "xml"));
      jFileChooser1.setAcceptAllFileFilterUsed(false);
      int retVal = jFileChooser1.showOpenDialog(this);  
      if (retVal == jFileChooser1.APPROVE_OPTION){
        retorno = jFileChooser1.getSelectedFile().getAbsolutePath();
        txtArquivo.setText(retorno);
      }
    }//GEN-LAST:event_btnSelArquivoActionPerformed

  private void btnCarregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCarregarActionPerformed
    Timer.start();
    SaxParser p = new SaxParser();
    p.parse(txtArquivo.getText());
    Timer.stop();
    lblTempo.setText(Timer.dump());
    funcoes.informa(this, "Carga Concluída");
    
    String txt = "";
    for(Iterator it = p.temp.keySet().iterator(); it.hasNext();) {        
        String chave = (String)it.next();        
        txt += chave + " ==> " + p.temp.get(chave) + "\n";
        System.out.println(chave + " ==> " + p.temp.get(chave));
    }    
    jLabel2.setText(txt);
  }//GEN-LAST:event_btnCarregarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new principal().setVisible(true);
            }
        });
    }
    
    public void incPB(){
      //jProgressBar1.setValue(jProgressBar1.getValue() + 1);
      //jProgressBar1.repaint();
    }
  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JButton btnCarregar;
  private javax.swing.JButton btnSelArquivo;
  private javax.swing.JInternalFrame jInternalFrame1;
  private javax.swing.JLabel jLabel1;
  private javax.swing.JLabel jLabel2;
  private javax.swing.JLabel jLabel3;
  private javax.swing.JScrollPane jScrollPane2;
  private javax.swing.JLabel lblTempo;
  private javax.swing.JTextField txtArquivo;
  private javax.swing.JTextArea txtPesquisadores;
  // End of variables declaration//GEN-END:variables
}
